typedef unsigned long uint64;

typedef enum {
    B_UNUSED = 0,
    B_EMPTY,
    B_LOADING,
    B_LOADED,
    B_SORTING,
    B_SORTED,
    B_WRITING,
    B_BROKEN
} mb_stat;

typedef struct membuf {
    uint64 size;
    void* buf;
    uint64 numa_id;
    pthread_mutex_t mtx;
    mb_stat stat;
} membuf;

typedef struct thread {
    pthread_t thread_id;
    int numa_id;
    int arg;
    void *retarder0;
    void *retarder1;
    void *retval;
} thread;

typedef struct mempool {
    uint64 buf_num;
    membuf* bufs;
} mempool;